//获取ul
let uu = document.querySelector('#container ul')
//1.发起请求获取列表数据

//2.根据列表数据展示列表内容

//3.需要将商品的productId绑定到元素上

//4.点击元素进行跳转,跳到detail页面 并且要携带productId
let el = "";
fetch('http://chst.vip:1234/api/getinlanddiscount')
    .then(body => body.json())
    .then(res => {
        console.log(res)
        res.result.forEach(item => {
            let regExp = /(?<=imgurl=)[^'"]*/;
            console.log(item)
            // //处理图片
            // let r = item.productImg.match(regExp);
            // console.log(r)
            el += `<li>
            <a href="../pages/internalDiscountDetail.html?productid=${item.productId}">
               <div class="image"> ${item.productImg}</div>
                <div class="title"${item.productName}</div>
                <p class="price">${item.productPrice}</p>
                <p class="from">${item.productFrom}|${item.productTime}</p>
            </a>
        </li>`
        })
        uu.innerHTML = el;
    })
//事件委托注册事件

uu.onclick = function (e) {
    if (e.target.localName === 'li') {
        let _this = e.target;
        console.log(_this)

        //获取当前li标签的productid

        let id = _this.getAttribute('productid')

        location.href = "../pages/internalDiscountDetail.html?productid=" + id
    }
}
//../pages/indexDetail.html?productid="